import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

//导入持久化依赖包
import VuexPersistence from "vuex-persist";
//实例化持久化插件对象
const vuexLocal = new VuexPersistence({
  storage: window.localStorage, //存储介质,
  key: "vuex", //存储到本地存储
});

export default new Vuex.Store({
  state: {
    token: "",
    name:"",
    isLoading:false,
  },
  mutations: {
    addtoken(state, data) {
      state.token = data.token
      state.name = data.username
    },
    removetoken(state){
      state.token = ""
      state.name = ""
    },
    setLoading(state,data){
      state.isLoading = data
    }
  },
  actions: {},
  plugins: [vuexLocal.plugin],
});
